<?php
include('../../__global.php');
include(SERVER_ROOT_PATH.'/include/config/ml_guang_config.php');
class guang_new extends ml_controller
{

    private $page;
    private $block;
    private $color;
    private $sex;
    private $minPrice;
    private $maxPrice;
    private $filter;
    private $order;
    private $_order_array = array('hot', 'new');

    public function initParam()
    {

        $page = (int)$this->input('page' , '' , 1);
        $page = $page < 1 ? 1 : $page;
        $page = $page > ML_GUANG_TOTAL_PAGE ? 1 : $page;
        $this->page = $page;
        $this->block = ($page-1) * ML_GUANG_BLOCK;
        $this->color = $this->input('color','G', '');
        $this->sex = $this->input('sex','G', '');
        $this->order = $this->input('order','G','hot');
        $this->maxPrice = $this->input('maxPrice','G', '');
        $this->minPrice = $this->input('minPrice','G', '');
        $this->filter = $this->input('filter','G', '');
        define('ML_SHOW_GOODS_FRM', 'pb'.$this->block);
    }
    public function checkParam()
    {
        $this->order = in_array($this->order, $this->_order_array) ? $this->order : 'hot';
        
        if(!Tool_input::param_base($this->maxPrice, array('type'=>ML_DATATYPE_DIGIT))){
            $this->maxPrice = '';
        }
        if(!Tool_input::param_base($this->minPrice, array('type'=>ML_DATATYPE_DIGIT))){
            $this->minPrice = '';
        }
    }
    public function main()
    {
        global $ML_GUANG_PAGETITLE;
        //行为LOG start
        $aTarget = array(
            'order' => $this->order,
            'page' => $this->page,
        );
        if(!empty($this->color))
            $aTarget['color'] = $this->color;
        if(!empty($this->sex))
            $aTarget['sex'] = $this->sex;
        if((!empty($this->minPrice)) || (!empty($this->maxPrice))){
            $aTarget['price'] = trim($this->minPrice.'_'.$this->maxPrice, '_');
        }

        ml_tool_actionlog::view_guang($this->__visitor['uid'] , $aTarget);
        //行为LOG end

        $option = array('sort'=>$this->order,'tag'=>array($this->filter),'color'=>$this->color,'sex'=>$this->sex,'maxPrice'=>$this->maxPrice,'minPrice'=>$this->minPrice,'block'=>$this->block);        
        $oGuang = new ml_biz_guang();
        $oGuang->check($option);
        $content = $oGuang->main();
        $oPin = new ml_biz_pin_content();
        $tmp = $oPin->output($this->__visitor['uid'], $content['rows'], false);
        $tmp = ml_tool_pinOutput::groupPinByColumn($tmp , 4);
        //$data['page_type'] = $this->page_type;
        //$data['hot_tag'] = ml_factory::load_standard_conf('lm_guangHotTag');
        $data['name'] = '逛街啦';
        //$data['pagetitle'] = $ML_GUANG_PAGETITLE[$this->page_type];
        $data['pins'] = $tmp;
        $data['minPrice'] = $this->minPrice;
        $data['maxPrice'] = $this->maxPrice;//目前的价格是写死的，以后切到后台
        $data['color'] = $this->color;
        $data['sex'] = $this->sex;
        $data['filter'] = $this->filter;
        $data['order'] = $this->order;
        $data['noh1'] = true;//logo无h1标签

        global $ML_GUANG_CATELOG;
        $catelogs = $ML_GUANG_CATELOG;
        foreach ( $catelogs as $key => $catelog ) {
            $ctag2tag = ml_tool_getdata::mlJsonData ( 'ctg2tag' . $catelog, 'ctg2tag' );
            $data ['ctgtag'] [$key]['list'] = $ctag2tag [0] ['list'];
        }

        $data['ctgtag'] = ml_factory::load_standard_conf('op_guangHotTag');


        $data['PAGER'] = array(
                'total_page' => ceil($content['total']/ML_GUANG_PAGESIZE/ML_GUANG_BLOCK),
                'cur_page' => $this->page,
                'url' => ml_tool_urlMaker::guang_filter('guang_new' , '' , $this->maxPrice , $minPrice , $this->color , $this->filter , $this->order)
            );
        
        $total_block = ceil($content['total']/ML_GUANG_PAGESIZE);
        $this->set_scope_var('$minPrice' , $this->minPrice);
        $this->set_scope_var('$maxPrice' , $this->maxPrice);
        $this->set_scope_var('$color' , $this->color);
        $this->set_scope_var('$filter' , $this->filter);
        $this->set_scope_var('$order' , $this->order);

        $this->set_scope_var('$totalPage' , ceil($total_block/ML_GUANG_BLOCK));
        $this->set_scope_var('$currentPage' , $this->page);
        $this->set_scope_var('$segment' , 1);
        $this->set_scope_var('$lastSegment' , $this->block == $total_block - 1 ? true : false);
        //$this->set_scope_var('$page_type' , $this->page_type);

        $this->set_page_title('逛街啦 - 最潮女装分享');
        $this->page_output('lm::public' , $data);
    }

}
new guang_new();
?>